//
//  MainViewController.swift
//  微博项目
//
//  Created by mac on 16/1/11.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    
    //按钮的监听事件
    @objc private func plusBtnDidClick(){
    print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
//        print(tabBar.classForCoder)  -------
        
        //实例化一个MainTabBar  的对象
        let mainTabBar = MainTabBar()
        
        //通过KVC赋值  把UITabBar 变成了MainTabBar
        
        setValue(mainTabBar, forKey:"tabBar")
        
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        
        addChildViewControllers()

//        print(tabBar.classForCoder) ---------
        
        
    }
//    private func addChildViewController() {
//        let vc = HomeViewController()
//        vc.title = "首页"
//        vc.tabBarItem.image = UIImage(named:"tabbar_home")
//     
//       addChildViewController(UINavigationController(rootViewController: vc))
//        
//    }

    private func addChildViewControllers() {
        
        addChildViewController(HomeViewController(),title:"首页",imageName:"tabbar_home")
        
        addChildViewController(MessageViewController(),title:"消息",imageName:"tabbar_message_center")
        
        
        addChildViewController(DiscoverViewController(),title:"发现",imageName:"tabbar_discover")
    addChildViewController(ProfileViewController(),title:"我",imageName:"tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController ,title:String , imageName:String) {
        
        vc.title = title
        //设置图片
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置item选中的图片  手写代码修改图片的显示样式
        self.tabBar.tintColor = UIColor.orangeColor()
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
}
